package cn.school.thoughtworks.section2;

import com.sun.org.apache.regexp.internal.RE;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class PracticeB {
    Map<String, Integer> countSameElements(List<String> collection1) {
        //实现练习要求，并改写该行代码。
        Map<String,Integer> sameElement=new HashMap<String,Integer>();
        for(int i=0;i<collection1.size();i++){
            if (collection1.get(i).length()>1){
                String[] strings=collection1.get(i).split("-");
                sameElement.put(strings[0],Integer.parseInt(strings[strings.length-1]));
            }else {
                Integer sum=sameElement.get(collection1.get(i));
                sameElement.put(collection1.get(i), sum==null?1:sum+1);
            }

        }
        return sameElement;

    }
}

